<?php
include_once '../../mainfile.php';
include (XOOPS_ROOT_PATH . "/header.php");
require ("include/xmlwriterclass.php");
require ("include/rss_writer_class.php");

/*
 *  First create an object of the class. 
 */
$rss_writer_object = & new rss_writer_class;

/*
 *  Choose the version of specification that the generated RSS document should conform.
 */
$rss_writer_object->specification = '1.0';

/*
 *  Specify the URL where the RSS document will be made available.
 */
$rss_writer_object->about = XOOPS_URL . '/modules/local_news/channels.xml';

/*
 *  Specify the URL of an optional XSL stylesheet.
 *  This lets the document be rendered automatically in XML capable browsers.
 */
$rss_writer_object->stylesheet = XOOPS_URL . '/modules/local_news/include/rss1html.xsl';

/*
 *  You may declare additional namespaces that enable the use of more property
 *  tags defined by extension modules of the RSS specification.
 */
$rss_writer_object->rssnamespaces['dc'] = 'http://purl.org/dc/elements/1.1/';

/*
 *  Define the properties of the channel.
 */
$properties = array ();
$properties['description'] = $xoopsModuleConfig['stationLetters'] . ' Southeast News Stories';
$properties['link'] = XOOPS_URL;
$properties['title'] = $xoopsModuleConfig['stationLetters'] . '-FM Southeast News Feeds';
$properties['dc:date'] = date("m/d/Y");
$rss_writer_object->addchannel($properties);

/*
 *  If your channel has a logo, before adding any channel items, specify the logo details this way.
 */
/*$properties = array ();
$properties['url'] = 'http://www.phpclasses.org/graphics/logo.gif';
$properties['link'] = 'http://www.phpclasses.org/';
$properties['title'] = 'PHP Classes repository logo';
$properties['description'] = 'Repository of components and other resources for PHP developers';
$rss_writer_object->addimage($properties);
*/

/*
 *  Then add your channel items one by one.
 */

//GET SYNDICATED NEWS STORIES 
if ($xoopsModuleConfig['enableSyndication'] == 1) {
	$link = mysql_connect($xoopsModuleConfig['syndicationDB_Host'], $xoopsModuleConfig['syndicationDB_User'], $xoopsModuleConfig['syndicationDB_Passaword']) or ($error = mysql_error());
	$Query = "SELECT ID, tease, publish_date, headline, dateline FROM CA_SE_News WHERE storyID NOT LIKE '" . strtoupper($xoopsModuleConfig['stationLetters']) . "%' AND soundfile != '' ORDER BY publish_date DESC LIMIT " . $xoopsModuleConfig['NISR'] . "";
	mysql_select_db($xoopsModuleConfig['syndicationDB']) or ($error = "Could not select database");
	$result = mysql_query($Query, $link) or ($error = "Query failed");

	if ($result) {
		$properties = array ();
		while ($myrow = mysql_fetch_array($result, MYSQL_ASSOC)) {
			$properties['description'] = $myrow['dateline'] . " (" . date("m/d/Y", $myrow['publish_date']) . ") " . html_entity_decode($myrow['tease'], ENT_QUOTES, 'UTF-8');
			$properties['link'] = XOOPS_URL . '/modules/local_news/index.php?op=sideBlock&syndicated=true&ID=' . $myrow['ID'];
			$properties['title'] = html_entity_decode($myrow['headline'], ENT_QUOTES, 'UTF-8');
			$properties['dc:date'] = date("m/d/Y", $myrow['publish_date']);
			$rss_writer_object->additem($properties);
		}
		mysql_free_result($result);
		mysql_close($link);
	}

}

/*
 *  If your channel has a search page, after adding the channel items, specify a search form details this way.
 */

/*
 *  The name property if the name of the text input form field on which the user will enter the search word.
 */
/*
$properties['name'] = 'words';
$properties['link'] = 'http://www.phpclasses.org/search.html?go_search=1';
$properties['title'] = 'Search for:';
$properties['description'] = 'Search in the PHP Classes repository';
$rss_writer_object->addtextinput($properties);
*/
/*
 *  When you are done with the definition of the channel items, generate RSS document.
 */
if ($rss_writer_object->writerss($output)) {

	/*
	 *  If the document was generated successfully, you may now output it.
	 */
	Header('Content-Type: text/xml; charset="' . $rss_writer_object->outputencoding . '"');
	Header('Content-Length: ' . strval(strlen($output)));
	echo $output;
} else {

	/*
	 *  If there was an error, output it as well.
	 */
	Header('Content-Type: text/plain');
	echo ('Error: ' . $rss_writer_object->error);
}
?>